import 'package:flutter/material.dart';
import 'package:qqjdflutter/model/home_page_model.dart';

import '../config/jd_api.dart';
import '../net/net_request.dart';

class HomePageProvider with ChangeNotifier{
  HomePageModel? model;
  bool isLoading = false;
  bool isError = false;
  String errorMsg = "";

  loadHomePageData(){
    isLoading = true;
    isError = false;
    errorMsg = "";
    NetRequest().reqeustData(JdApi.HOME_PAGE).then((res){
      if(res.code == 200){
        print('首页数据${res.data}');
        //print('首页数据${res.code}');
        isLoading = false;
        isError = false;
        model = HomePageModel.fromJson(res.data);
        print("model${model?.toJson()}");
      }
      notifyListeners();
    }).catchError((error){
      print(error);
      errorMsg = error;
      isLoading = false;
      isError = true;
      notifyListeners();

    });
  }
}